﻿//-----------------------------------------------------------------------
// <copyright file="DeixeiWebContext.cs" company="deixei.com">
//     Copyright (c) deixei.com. All rights reserved.
// </copyright>
// <author>Marcio Parente</author>
//---------------------------------------------------------------------
namespace Deixei.Web
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Policy;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Deixei;
    

    public class DeixeiWebContext
    {

        private UrlHelper urlHelper;

        public DeixeiWebContext(RequestContext requestContext)
        {
            this.Initialize(requestContext);
        }


        public void Initialize(RequestContext requestContext)
        {
            CommonUtil.CheckForNull(requestContext, "requestContext");
            this.RequestContext = requestContext;
            RouteData routeData = requestContext.RouteData;

        }

        public string CurrentUsername 
        {
            get 
            {
                return WebSecurity.Username;
            }
        }


        public RequestContext RequestContext
        {
            get;
            private set;
        }

        public string RootPath
        {
            get
            {
                return VirtualPathUtility.ToAbsolute("~/");
            }
        }
        
        public UrlHelper Url
        {
            get
            {
                if (this.urlHelper == null)
                {
                    this.urlHelper = new UrlHelper(this.RequestContext);
                }
                return this.urlHelper;
            }
        }

        public string CurrentController
        {
            get 
            {
                return (string)this.RequestContext.RouteData.Values["controller"];
            }
        }
        public string CurrentAction
        {
            get
            {
                return (string)this.RequestContext.RouteData.Values["action"];
            }
        }
        public string CurrentArea
        {
            get
            {
                var area = this.RequestContext.RouteData.DataTokens["area"] ?? "";
                return (string)area;
            }
        }

    }
}
